import * as actionTypes from '../../actions/ActionTypes';

import {handleActions} from 'redux-actions';

const defData = {  //职位推荐初始值
    postionList: []
}

export const ShowPostion = handleActions({
    [actionTypes.SEL_POSTION]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加postionList
                action.payload.postionList = state.data.postionList.concat(action.payload.postionList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData};
        }
    }
}, {ret: true, isloading: true, data: defData});


const defData1 = {  //谁看了我的简历
    postionList: []
}

export const ShowoNewPostion = handleActions({
    [actionTypes.SEL_NEWPOSTION]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加postionList
                action.payload.postionList = state.data.postionList.concat(action.payload.postionList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData1};
        }
    }
}, {ret: true, isloading: true, data: defData1});

const defData2 = {  //最新职位初始值 
    companyList: []
}

export const ShowoCompany = handleActions({
    [actionTypes.SEL_COMPANY]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加companyList
                action.payload.companyList = state.data.companyList.concat(action.payload.companyList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData2};
        }
    }
}, {ret: true, isloading: true, data: defData2});

const defData3 = {//职位详情
    xzPostion: {},
    CollectState: '',
    selisSend: '',
    isloading: true//是否读取ing1
}

export const SelPosInfoReducer = handleActions({
    [actionTypes.SEL_POSTIONINFO_MOB]: {//职位详情action
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData3};
        }
    },
    [actionTypes.INSERT_COLLECT_MOB]: {//添加收藏action
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData3};
        }
    },
    [actionTypes.DELETE_COLLECT_MOB]: {//删除收藏action
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData3};
        }
    },
    [actionTypes.SEND_POSTION]: {//投递简历action
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData3};
        }
    }
}, {ret: true, isloading: true, statusText: '默认', data: defData3});

//感兴趣的职位
const defData4 = {
    plist: []
};

export const SelInfoByNameReducer = handleActions({
    [actionTypes.SEL_INTERESTING_MOB]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw() {
            return {ret: false, isloading: false, data: defData4};
        }
    }
}, {ret: true, isloading: true, data: defData4});

const defData5 = {//公司详情
    xzCompany: {},
    followState: '',
    isloading: true//是否读取ing1
}

export const SelCompanyInfoReducer = handleActions({
    [actionTypes.SEL_COMPANYINFO_MOB]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData5};
        }
    },
    [actionTypes.INSERTSELECTIVE]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData5};
        }
    },
    [actionTypes.DELETEFOLLOWBYKEYMOB]: {
        next(state, action) {
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, statusText: "报错", data: defData5};
        }
    }
}, {ret: true, isloading: true, statusText: '默认', data: defData5});

//公司热招职位
const defData9 = {
    list: []
}

export const SelPostionCompanyIdReducer = handleActions({
    [actionTypes.SEL_POSTION_COMPANYID_MOB]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加list
                action.payload.list = state.data.list.concat(action.payload.list);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData9};
        }
    }
}, {ret: true, isloading: true, data: defData9});

//根据公司经营领域查询职位
const defData10 = {
    postionList: []
}
export const SelpostionByFieldReducer = handleActions({
    [actionTypes.SEL_POSTION_INDEX_MOB]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加postionList
                action.payload.postionList = state.data.postionList.concat(action.payload.postionList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defDdefData10ata9};
        }
    }
}, {ret: true, isloading: true, data: defData10});

const defData11 = {  //按条件查询
    postionList: []
}

export const SelposMobReducer = handleActions({
    [actionTypes.SEL_POSMOB]: {
        next(state, action) {
            if (action.payload.page != 1) {//不是第一页时追加postionList
                action.payload.postionList = state.data.postionList.concat(action.payload.postionList);
            }
            return {ret: true, isloading: false, data: action.payload};
        },
        throw(state, action) {
            return {ret: false, isloading: false, data: defData11};
        }
    }
}, {ret: true, isloading: true, data: defData11});